$(function(){
	var sliderBox = $(".slider");
	var imgArray = new Array();	
	var i=0;//计数器
	$(".sliderData img").each(function(){
		var	$source = $(this).attr("src");
		imgArray[i]=$source;
		i++;
	});
	changeScreen(sliderBox,imgArray,0);
	
	$(".sliderMenu li").click(function(){
	_this = $(this);
	_this.addClass("current").siblings().removeClass("current");
	var index = getIndex(_this);
	textChange(index);
	sliderBox.find(".loading").load("loading/loading.html",function(){
		setTimeout(function(){
			
			changeScreen(sliderBox,imgArray,index);		
			sliderBox.find(".loading").empty();
			},1000);
			});
	});
	
	$(".sliderBtnRight").bind("click",function(){
		var _this = $(this);
		var a =	Next(_this,sliderBox,imgArray);	
		textChange(a);
		return false;
	});
	$(".sliderBtnLeft").bind("click",function(){
		var _this = $(this);
		var a = Prev(_this,sliderBox,imgArray);	
		textChange(a);
		return false;
	});
});
function Next(o,sliderBox,imgArray){
	var current = $(".sliderMenu li.current").index()+1;	
	if(current>=$(".sliderMenu li").size()){
		current = 0;
		}
			
	 btnAction(o,current,sliderBox,imgArray);
	 return current;
}
function Prev(o,sliderBox,imgArray){
	var current = $(".sliderMenu li.current").index()-1;	
	if(current <0){
		current=$(".sliderMenu li").length-1;
		}
	btnAction(o,current,sliderBox,imgArray);
	 return current;
}
function btnAction(a,current,sliderBox,imgArray){
	sliderBox.find(".sliderMenu li").eq(current).addClass("current").siblings().removeClass("current");
	var index = $(".sliderMenu li.current").index();
	
	sliderBox.find(".loading").load("loading/loading.html",function(){
		setTimeout(function(){
			changeScreen(sliderBox,imgArray,current);		
			sliderBox.find(".loading").empty();
			
			},1000);
			});
	current = index;
	
	return current;
}
function getIndex(e){
	var Index = e.index();
	return Index;
}

function changeScreen(sliderBox,imgArray,index){
	sliderBox.css({"background-image":"url("+imgArray[index]+")"})
}

function textChange(e){
	var SingleWidth = $(".sliderTextCont li").width();
	$(".sliderTextCont ul").stop().animate({"left":-SingleWidth*e});	
}
